﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MessageServer.utilities;

namespace MessageServer.config
{
    public class TuningParams
    {
        //This class is a singleton for every instance run.
        private static TuningParams GLOBALCONFIG = new TuningParams(""); //load correctly

        public static TuningParams getConfig()
        {
            return GLOBALCONFIG;
        }

        const String MIN_SOCKET_WORKERS = "Minimum Socket Workers";
        const String MAX_SOCKET_WORKERS = "Maximum Socket Workers";
        const String WAIT_FOR_THREADS = "Wait For Threads";
        const String MAX_CONCURRENT_CONNS = "Maximum Concurrent Connections";
        const String SOCKET_WAIT_FOR_DATA = "Wait for Data at socket";
        const String MIN_SELECTOR_THREADS = "Minimum Selector Threads";
        const String MAX_SELECTOR_THREADS = "Maximum Selector Threads";
        const String SELECTOR_POLL = "Selector Poll Time";
        const String MAX_WORKERS_PER_SELECTOR = "Maximum Workers Per Selector";
        const String MIN_PIPELINE_THREADS = "Minimum Pipeline threads";
        const String MAX_PIPELINE_THREADS = "Maximum Pipeline threads";

        Properties _config = new Properties();

        private TuningParams(String file)
        {
            //TODO: Load properties from file
            _config.setProperty(MIN_SOCKET_WORKERS, 5);
            _config.setProperty(MAX_SOCKET_WORKERS, 20);
            _config.setProperty(WAIT_FOR_THREADS, 100); //in ms
            _config.setProperty(MAX_CONCURRENT_CONNS, 1000);
            _config.setProperty(SOCKET_WAIT_FOR_DATA, 100000); //in microseconds
            _config.setProperty(MIN_SELECTOR_THREADS, 10);
            _config.setProperty(MAX_SELECTOR_THREADS, 10);
            _config.setProperty(SELECTOR_POLL, 100); //in ms

            _config.setProperty(MIN_PIPELINE_THREADS, 10);
            _config.setProperty(MAX_PIPELINE_THREADS, 20);
        }

        public int MinSocketWorkers { get { return _config.getIntProperty(MIN_SOCKET_WORKERS); } }
        public int MaxSocketWorkers { get { return _config.getIntProperty(MAX_SOCKET_WORKERS);  } }
        public int WaitForThread { get { return _config.getIntProperty(WAIT_FOR_THREADS); } }
        public int MaxConcurrentConns { get { return _config.getIntProperty(MAX_CONCURRENT_CONNS); } }
        public int socketWaitForData { get { return _config.getIntProperty(SOCKET_WAIT_FOR_DATA); } }
        public int MinSelectorThreads { get { return _config.getIntProperty(MIN_SELECTOR_THREADS); } }
        public int MaxSelectorThreads { get { return _config.getIntProperty(MAX_SELECTOR_THREADS); } }
        public int SelectorPollInterval { get { return _config.getIntProperty(SELECTOR_POLL); } }
        public int MaxWorkersPerSelector { get { return _config.getIntProperty(MAX_WORKERS_PER_SELECTOR); } }
        public int MinPipelineThreads { get { return _config.getIntProperty(MIN_PIPELINE_THREADS); } }
        public int MaxPipelineThreads { get { return _config.getIntProperty(MAX_PIPELINE_THREADS); } }
    }
}
